using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Beta_fundies_controls_Quotes_MainPage : Controls.DataManagerArchiveControl
{
    protected override void ItemChanged()
    {
        Refresh();
    }
    private DateTime ArchiveDate
    {
        get
        {
            DateTime archive;
            if (Helpers.QueryStringHelper.TryGetDateTime("date", out archive))
            {
                return archive;
            }
            else
            {
                return DateTime.Today;
            }
        }
    }

    private int CurrentPage
    {
        get
        {
            int page;
            if (Helpers.QueryStringHelper.TryGetInt32("page", out page))
            {
                return page;
            }
            else
            {
                return 1;
            }
        }
    }

    public void Refresh()
    {
        if (CurrentArchive != null)
        {
            mviewArchive.SetActiveView(viewArchive);
            lblTitle.Text = string.Format("<u>{0}</u><br />{1:MMMM yyyy}", CurrentArchive.Title, ArchiveDate);
            Page.Title = string.Format("{0} {1:MMMM yyyy}", CurrentArchive.Title, ArchiveDate);

            DAL.DataManagerPage<DAL.Quote> myQuotes = DAL.Quotes.GetQuotesByMonth(CurrentArchive, ArchiveDate, CurrentPage);

            Pager1.CurrentPage = CurrentPage;
            Pager1.UrlFormat = "~/fundies/default.aspx?date=" + ArchiveDate.ToString("yyyy/MM") + "&page={0}";
            Pager1.TotalPages = myQuotes.Pages;

            Pager2.CurrentPage = Pager1.CurrentPage;
            Pager2.UrlFormat = Pager1.UrlFormat;
            Pager2.TotalPages = Pager1.TotalPages;

            QuoteListl1.SetDataSource(myQuotes.Items);
        }
        else
        {
            Page.Title = "Archive Not Found";
            mviewArchive.SetActiveView(viewError);
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            DAL.Archive myArchive = GetItemFromQueryString();
            if (myArchive == null)
            {
                myArchive = DAL.Archives.Item(1);
            }
            CurrentArchive = myArchive;
        }
    }
}
